package dao.daoImpl;

import common.DataSourceUtils;
import dao.ClazzMapper;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import pojo.Department;
import pojo.LogFamily;

import java.sql.SQLException;
import java.util.List;

/**
 * Created by Administrator on 2017-12-10.
 */
public class ClazzMapperImpl implements ClazzMapper {

    @Override
    public List<LogFamily> getAllLogFamily() throws SQLException {
        QueryRunner qr=new QueryRunner(DataSourceUtils.getDataSource());
        String sql="select * from logFamily";
        return qr.query(sql,new BeanListHandler<LogFamily>(LogFamily.class));
    }

    @Override
    public int deleteLogFamily(int id) throws SQLException {
        QueryRunner qr=new QueryRunner(DataSourceUtils.getDataSource());
        String sql=" delete from logFamily where id=?";
        return qr.update(sql,id);
    }

    @Override
    public int deleteLogDepartment(int id) throws SQLException {
        QueryRunner qr=new QueryRunner(DataSourceUtils.getDataSource());
        String sql=" delete from department where id=?";
        return qr.update(sql,id);
    }

    @Override
    public int addLogFamily(String logFamily) throws SQLException {
        QueryRunner qr=new QueryRunner(DataSourceUtils.getDataSource());
        String sql=" insert into logFamily (logFamily) values (?)";
        return qr.update(sql,logFamily);
    }

    @Override
    public int addDepartment(String department) throws SQLException {
        QueryRunner qr=new QueryRunner(DataSourceUtils.getDataSource());
        String sql=" insert into department (department) values (?)";
        return qr.update(sql,department);
    }

    @Override
    public List<Department> getAllDepartment() throws SQLException {
        QueryRunner qr=new QueryRunner(DataSourceUtils.getDataSource());
        String sql="select * from department";
        return qr.query(sql,new BeanListHandler<Department>(Department.class));
    }
}
